/*
 * @Author: your name
 * @Date: 2020-11-26 12:53:30
 * @LastEditTime: 2021-03-07 14:43:07
 * @LastEditors: Please set LastEditors
 * @Description: 多彩校园获取用户ID
 * @FilePath: \relearnJS\perfectCampus\test.js
 */
function getUserInfo(phone, password, responseText) {
    if (!phone || !password) {
        responseText.innerHTML = "账号/密码不能为空"
        return;
    }
    var data = {
            loginAccount: phone,
            password: password
        },
        userInfo = {
            campusId: "",
            customerName: "",
            customerId: "",
            customerPhone: "",
            token: ""
        },
        token = "",
        xhr = new XMLHttpRequest();
    xhr.withCredentials = true;

    xhr.open("POST", "http://dcxy-customer-app.dcrym.com/app/customer/login");
    xhr.setRequestHeader("clientSource", "{}");
    xhr.setRequestHeader("Content-Type", " application/json");

    xhr.addEventListener("readystatechange", function () {
        if (this.readyState === 4) {
            // console.log(JSON.parse(this.responseText));
            let result = JSON.parse(this.responseText).data
            Object.keys(userInfo).forEach(v => {
                if (v === "campusId") {
                    userInfo[v] = result.areaId
                } else {
                    userInfo[v] = result[v]
                }
            })
            console.log('success');
            console.log(userInfo);
            responseText.innerHTML = JSON.stringify(userInfo, null, 4).replace(/"/g, '')
            // return userInfo;
        } else {
            responseText.innerHTML = "账号/密码错误"
        }
    });
    xhr.send(JSON.stringify(data));
}